/*
 * @Author: your name
 * @Date: 2021-11-24 11:43:33
 * @LastEditTime: 2022-01-19 16:06:06
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \vue-antd-admin-y\src\services\user.js
 */

import {LOGIN, ROUTES,checkRoleApi,loginOutApi} from '@/services/api'
import { routerAlways } from '@/router/async/router.always'
import { loadRoutes } from "@/utils/routerUtil";
import {request, METHOD
  // , removeAuthorization
} from '@/utils/request'

/**
 * 登录服务
 * @param name 账户名
 * @param password 账户密码
 * @returns {Promise<AxiosResponse<T>>}
 */
export  function login(userName, passWord) {
  return request(LOGIN, METHOD.POST, {
    userName: userName,
    passWord: passWord
  })
}

export async function getRoutesConfig() {
  let res =  await request(ROUTES, METHOD.POST)
  if(res.code == 200){    //所有路由上下级
    const routesConfig = [
      {
        router: "root", // 根页
        children: [
          ...routerAlways,
          ...res.data
        ],
      },
    ];
    loadRoutes(routesConfig);
}

}
export  function checkRole() {
  return request(checkRoleApi, METHOD.POST)
}

 


/**
 * 退出登录
 */
export function loginOut() {

  
  return request(loginOutApi, METHOD.POST)
 

}
export default {
  login,
  loginOut,
  getRoutesConfig,
  checkRole
}
